#include<iostream>

using namespace std;
#define int long long

const int N = 2e5 + 10;
int n;
int f[N];
signed main()
{
    cin >> n;
    for(int i = 1;i <= n;i ++)
    {
        int x; cin >> x;
        f[i] = f[i-1] + x;
    }
    int ret = -1e20;
    int prevmin = 0;
    for(int i = 1;i <= n;i ++)
    {
        ret = max(ret , f[i] - prevmin);
        prevmin = min(prevmin , f[i]);
    }
    cout << ret << endl;
    return 0;
}